<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><fmt:message key="rental.listofrentals" /></title>
    </head>
    <body>
        <div class="container">
            <h1 class="h1"><fmt:message key="rental.listofrentals" /></h1>
            <div>
                <a href="<c:url value="/rental/add"/>">
                    <img src="<c:url value="/resources/pictures/add.png" />" title="<fmt:message key="rental.addNew" />" /> <fmt:message key="rental.addNew" />
                </a>
            </div>

            <c:if test="${empty rentals}">
                <fmt:message key="rental.notrentalsavailable" />
            </c:if>
            <c:if test="${not empty rentals}">

                <c:url var="saveUrl" value="/rental/search" />
                <form:form method="POST" role="form" action="${saveUrl}" class="form-inline" modelAttribute="searchModel" commandName="searchModel">
                    <div class="form-group">
                        <form:label path="customer" ><fmt:message key="customer" />:</form:label>
                        <form:select path="customer" class="form-control">
                            <form:options items="${customersMap}" />
                        </form:select>
                    </div>
                    <div class="form-group">
                        <form:label path="machine" ><fmt:message key="machine" />:</form:label>
                        <form:select path="machine" class="form-control" items="${machinesMap}" />
                    </div>
                    <div class="form-group">        
                        <button type="submit" class="btn btn-default"><fmt:message key="search" /></button>
                    </div>
                </form:form>

                <table class="table table-striped">                
                    <th>
                        <fmt:message key="detail" />
                    </th>
                    <th>
                        <fmt:message key="customer" />
                    </th>
                    <th>
                        <fmt:message key="machine" />
                    </th>
                    <th>
                        <fmt:message key="rental.dateOfRent" />
                    </th>
                    <th>
                        <fmt:message key="rental.duration" />
                    </th>
                    <th>
                        <fmt:message key="rental.dateOfReturn" />
                    </th>
                    <th>
                        <fmt:message key="edit" />
                    </th>
                    <c:forEach var="r" items="${rentals}">
                        <tr>
                            <td>
                                <a href="<c:url value="/rental/detail/${r.id}"/>">
                                    <img src="<c:url value="/resources/pictures/detail.png" />" title="<fmt:message key="detail" />" /> <fmt:message key="detail" />
                                </a>
                            </td>
                            <td>
                                <a href="<c:url value="/customer/detail/${r.customer.id}"/>"><c:out value="${r.customer.firstName}"/> <c:out value="${r.customer.lastName}"/></a>
                            </td>
                            <td>
                                <a href="<c:url value="/machine/detail/${r.machine.id}"/>"><c:out value="${r.machine.code}"/> <c:out value="${r.machine.brand}"/> <c:out value="${r.machine.model}"/></a>
                            </td>
                            <td>
                                <c:out value="${r.dateOfRent}"/>
                            </td>
                            <td>
                                <c:out value="${r.duration}"/>
                            </td>
                            <td>
                                <c:out value="${r.dateOfReturn}"/>
                            </td>
                            <td>
                                <a href="<c:url value="/rental/edit/${r.id}"/>">
                                    <img src="<c:url value="/resources/pictures/edit.png" />" title="<fmt:message key="edit" />" /> <fmt:message key="edit" />
                                </a>
                            </td>
                        </tr>
                    </c:forEach>
                </table>
            </c:if>
        </div>
    </body>
</html>
